import { createRouter, createWebHashHistory } from "vue-router";

const Login = () => import("../pages/Login.vue");
const Home = () => import("../pages/Home.vue");
const routes = [
  { path: "/", name: "home", component: Home },
  { path: "/login", name: "login", component: Login },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  if (sessionStorage.getItem("token")) {
    next();
  } else {
    if (to.path === "/login") {
      next();
    } else {
      next({ name: "login" });
    }
  }
});
export default router;
